package org.ytor.core.sqlflow.executor.ds;

import org.springframework.jdbc.datasource.DataSourceUtils;

import javax.sql.DataSource;
import java.sql.Connection;

/**
 * created by yangtong on 2025/8/11 21:06:55
 * <br/>
 * 基于 SPRING 的数据源管理
 */
public class SpringDataSourceManager implements DataSourceManager {

    private final DataSource dataSource;

    public SpringDataSourceManager(DataSource dataSource) {
        this.dataSource = dataSource;
    }

    @Override
    public Connection get() {
        return DataSourceUtils.getConnection(dataSource);
    }

    @Override
    public void close(Connection conn) {
        DataSourceUtils.releaseConnection(conn, dataSource);
    }
}
